define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xilujob/job_apply/index' + location.search,
                    add_url: 'xilujob/job_apply/add',
                    edit_url: 'xilujob/job_apply/edit',
                    del_url: 'xilujob/job_apply/del',
                    multi_url: 'xilujob/job_apply/multi',
                    table: 'xilujob_job_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'job.job_name', title: __('Job_id'), operate: "LIKE"},
                        {field: 'person',title:'基本信息',align:'left',formatter: Controller.api.formatter.personal , operate: false},
                        {field: 'works',title:'工作经历',align:'left',formatter: Controller.api.formatter.works , operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6')}, formatter: Table.api.formatter.normal},
                       // {field: 'accepttime', title: __('Accepttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'rejecttime', title: __('Rejecttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                personal: function(value,row,index) {
                    var resume_data = row.resume.personal.age+' | '
                        + (row.resume.personal.work_experience?row.resume.personal.work_experience.name:'') + ' | '
                        + (row.resume.personal.education_level ? row.resume.personal.education_level.name : '') + ' | '
                        + (row.resume.personal.current_state?row.resume.personal.current_state.name:'');
                    var summary_content = row.resume.summary.content;
                    summary_content = summary_content.length>20 ? summary_content.substring(0,20)+'...' : summary_content;
                    var html = '<div class="media">';
                    html += '<a class="media-left" href="#">';
                    html += '<img width="50px" height="50px" src="'+Fast.api.cdnurl(row.resume.personal.avatar)+'" class="img-circle" alt="">';
                    //html += '<div>'+row.resume.job_intention.expect_salary.name+'</div>';
                    html += '</a>';

                    html += '<div class="media-body" style="width: auto">';
                    html += '<a href="'+Fast.api.fixurl('xilujob/resume/detail?ids='+row.resume.id)+'" class="btn-dialog" data-title="简历详情"><h4>'+row.resume.personal.realname+'</h4>';
                    html += '<p>'+resume_data+'</p></a>';
                    //html += '<p>求职期望：'+row.resume.job_intention.fav_city.allname+'</p>';
                    html += '<p><a title="'+row.resume.summary.content+'" style="width: 150px">'+summary_content+'</a></p>';
                    html += '</div>';
                    html += '</div>';
                    return html;
                },
                works: function(value,row,index){
                    if(!row.resume.works) return '';
                    var html = '';
                    for (var i=0;i<row.resume.works.length;i++){
                        var end = row.resume.works[i].end ? row.resume.works[i].end : "至今";
                        html += '<h5>'+row.resume.works[i].start+'-'+end+'   '+row.resume.works[i].company_name+' . '+row.resume.works[i].job_title+'</h5>';
                    }
                    return html;
                },
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});